package cn.fl.spl.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.product.service.ISplInfoService;
import cn.fl.spl.service.ISplPriSeaRuleCfgService;
import cn.fl.spl.transform.SplPriSeaRuleCfgVOTransform;
import cn.fl.spl.vo.SplPriSeaRuleCfgVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.spl.condition.SplPriSeaRuleCfgQC;
import fl.spl.facade.spl.dto.SplPriSeaRuleCfgDTO;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 经销商相关基础数据私海规则配置 控制层
 */
@Controller
@RequestMapping("/spl/splprisearulecfg")
public class SplPriSeaRuleCfgController extends BaseController {

    /**
     * SplPriSeaRuleCfg 服务层BEAN
     */
    @Autowired
    private ISplPriSeaRuleCfgService splPriSeaRuleCfgService;

    @Autowired
    private ISplInfoService splInfoService;

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("spl/splPriSeaRuleCfg/splPriSeaRuleCfgList");

        //事业部
        List<KeyValueVO> searchBuOrgList = this.splInfoService.searchBuOrgCdList();
        view.addObject("searchBuOrgList", searchBuOrgList);

        view.addObject("currOrgCd", CurrentThreadContext.getCurrentOrgCd());
        view.addObject("currBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());

        return view;
    }

    /**
     * 到新增修改页面
     */
    @RequestMapping(value = "/toAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("spl/splPriSeaRuleCfg/splPriSeaRuleCfgAdd");
        //事业部
        List<KeyValueVO> searchBuOrgList = this.splInfoService.searchBuOrgCdList();
        JSONArray buOrgCdsJson = JSONArray.fromObject(searchBuOrgList.toArray());
        view.addObject("buOrgList", buOrgCdsJson);
        view.addObject("currOrgCd", CurrentThreadContext.getCurrentOrgCd());
        view.addObject("currBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
        return view;
    }

    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {

        String id = request.getParameter("id");
        ModelAndView view = new ModelAndView("spl/splPriSeaRuleCfg/splPriSeaRuleCfgModify");
        view.addObject("id", id);
        //事业部
        List<KeyValueVO> searchBuOrgList = this.splInfoService.searchBuOrgCdList();
        JSONArray buOrgCdsJson = JSONArray.fromObject(searchBuOrgList.toArray());
        view.addObject("buOrgList", buOrgCdsJson);
        view.addObject("currOrgCd", CurrentThreadContext.getCurrentOrgCd());
        view.addObject("currBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
        SplPriSeaRuleCfgVO vo = this.splPriSeaRuleCfgService.selectById(Long.valueOf(id));
        view.addObject("splPriSeaRuleCfgVO",vo);
        view.addObject("voJson",JSONObject.toJSON(vo));
        return view;
    }

    /**
     * 到详情页面
     */
    @RequestMapping(value = "/toDetailPage.do", method = {RequestMethod.GET})
    public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {

        String id = request.getParameter("id");
        ModelAndView view = new ModelAndView("spl/splPriSeaRuleCfg/splPriSeaRuleCfgDetail");
        view.addObject("id", id);
        SplPriSeaRuleCfgVO vo = this.splPriSeaRuleCfgService.selectById(Long.valueOf(id));
        view.addObject("splPriSeaRuleCfgVO",vo);
        return view;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initList(HttpServletRequest request, HttpServletResponse response) {

        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String privateSeaNm = request.getParameter("privateSeaNm");
        String buOrgCd = request.getParameter("buOrgCd");
        String adminName = request.getParameter("adminName");

        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        SplPriSeaRuleCfgQC qc = new SplPriSeaRuleCfgQC();
        if (StringUtils.isNotEmpty(privateSeaNm)) {
            qc.setPrivateSeaNm(privateSeaNm);
        }
        if(StringUtils.isNotEmpty(buOrgCd)){
            qc.setBuOrgCd(buOrgCd);
        }
        page.setCondition(qc);

        Pager pager = this.splPriSeaRuleCfgService.searchListPage(page);
        List<SplPriSeaRuleCfgDTO> list = (List<SplPriSeaRuleCfgDTO>) pager.getResultList();
        List<SplPriSeaRuleCfgVO> splPriSeaRuleCfgVOS = null ;
        if(CollectionUtils.isNotEmpty(list)){
            splPriSeaRuleCfgVOS = SplPriSeaRuleCfgVOTransform.toVOList(list);
            //事业部
            List<KeyValueVO> searchBuOrgList = this.splInfoService.searchBuOrgCdList();
            Map<String,String> buOrgCdNmMap = new HashMap<>(searchBuOrgList.size());
            for(KeyValueVO valueVO : searchBuOrgList){
                buOrgCdNmMap.put(valueVO.getKey(),valueVO.getValue());
            }
            for(SplPriSeaRuleCfgVO splPriSeaRuleCfgVO : splPriSeaRuleCfgVOS){
                if(buOrgCdNmMap.containsKey(splPriSeaRuleCfgVO.getBuOrgCd())){
                    splPriSeaRuleCfgVO.setBuOrgCdNm(buOrgCdNmMap.get(splPriSeaRuleCfgVO.getBuOrgCd()));
                }
            }

        }
        ListPageVO<SplPriSeaRuleCfgVO> listPage = new ListPageVO<SplPriSeaRuleCfgVO>(splPriSeaRuleCfgVOS, pager.getTotalCount());
        BaseLogUtils.newWebLogger("加载列表页面").setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .setKeys("listPage", JSON.toJSONString(listPage))
                .info();
        return listPage;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
        SplPriSeaRuleCfgVO entity = null;
        try {
            entity = this.setAddParamsByRequest(request);
            entity.setTabNm("SPL_BSC_INFO");
            Long id = this.splPriSeaRuleCfgService.add(entity);
            result.setData(id);
            BaseLogUtils.newWebLogger("新增数据.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("新增对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("新增对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }

        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {

        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("数据不存在!");
            return result;
        }
        SplPriSeaRuleCfgVO entity = null;
        try {
            entity = this.setModifyParamsByRequest(request);
            entity.setId(Long.valueOf(id));
            boolean success = this.splPriSeaRuleCfgService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("修改失败!");
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
        }
        return result;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeById.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {

        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("主键不能为空!");
            return result;
        }
        try {
            this.splPriSeaRuleCfgService.removeById(Long.valueOf(id));
            BaseLogUtils.newWebLogger("删除数据.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();

        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("移除对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("移除对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }

        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("主键不能为空!");
            BaseLogUtils.newWebLogger("获取数据,主键不存在.[id=" + id + "]").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }

        try {
            SplPriSeaRuleCfgVO vo = this.splPriSeaRuleCfgService.selectById(Long.valueOf(id));
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("数据不存在!");
                BaseLogUtils.newWebLogger("获取数据,数据不存在.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
            if(StringUtils.isEmpty(vo.getReleasedReceiveDay())){
                vo.setReleasedReceiveDay(0L);
            }
            //事业部
            List<KeyValueVO> searchBuOrgList = this.splInfoService.searchBuOrgCdList();
            for(KeyValueVO keyValueVO : searchBuOrgList){
                if(keyValueVO.getKey().equals(vo.getBuOrgCd())){
                    vo.setBuOrgCdNm(keyValueVO.getValue());
                    break;
                }
            }
            result.setData(vo);
            BaseLogUtils.newWebLogger("获取数据.[id=" + id + "]").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("根据主键获取对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("根据主键获取对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }

        return result;
    }

    private SplPriSeaRuleCfgVO setAddParamsByRequest(HttpServletRequest request){
        SplPriSeaRuleCfgVO splPriSeaRuleCfgVO = this.comboVOParamsByRequest(request);
        splPriSeaRuleCfgVO.setCrtTm(new Date());
        splPriSeaRuleCfgVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        return splPriSeaRuleCfgVO ;
    }

    private SplPriSeaRuleCfgVO setModifyParamsByRequest(HttpServletRequest request){
        SplPriSeaRuleCfgVO splPriSeaRuleCfgVO = this.comboVOParamsByRequest(request);
        splPriSeaRuleCfgVO.setMdfTm(new Date());
        splPriSeaRuleCfgVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        return splPriSeaRuleCfgVO ;
    }

    private SplPriSeaRuleCfgVO comboVOParamsByRequest(HttpServletRequest request){
        SplPriSeaRuleCfgVO vo = null ;
        String privateSeaNm = request.getParameter("privateSeaNm");
        String buOrgCd = request.getParameter("buOrgCd") ;
        String receiveLimitUp = request.getParameter("receiveLimitUp");
        String isAutoRelease = request.getParameter("isAutoRelease");
        String isActiveRelease = request.getParameter("isActiveRelease") ;
        String againReceiveLimit = request.getParameter("againReceiveLimit");

        String unvisitReleaseDay = request.getParameter("unvisitReleaseDay");
        String uncapReleaseDay = request.getParameter("uncapReleaseDay") ;
        String hadCapedReleaseDay = request.getParameter("hadCapedReleaseDay");
        String releasedReceiveDay = request.getParameter("releasedReceiveDay") ;
        String capDelayDate = request.getParameter("capDelayDate") ;
        String crtPrjDelayDate = request.getParameter("crtPrjDelayDate") ;
        String remark = request.getParameter("remark");
        String customersLimitUp = request.getParameter("customersLimitUp");

        String visitRecDelayDate = request.getParameter("visitRecDelayDate");
        String receiveDefaultDay = request.getParameter("receiveDefaultDay");
        String isCanReceive = request.getParameter("isCanReceive");
        String uncrtprjReleaseDay = request.getParameter("uncrtprjReleaseDay");

        String autoRuleQCAndIsOr = request.getParameter("autoRuleQCAndIsOr") ;


        if(StringUtils.isEmpty(privateSeaNm)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则名称不能为空！");
        }
        if(StringUtils.isEmpty(buOrgCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则所属事业部不能为空！");
        }
        if(StringUtils.isEmpty(receiveLimitUp)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则领取限制不能为空！");
        }
        if(StringUtils.isEmpty(isCanReceive)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"是否支持领取私海不能为空！");
        }
        if(StringUtils.isEmpty(customersLimitUp)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则私海客户数限制不能为空！");
        }
        if(StringUtils.isEmpty(receiveDefaultDay)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则领取默认天数不能为空！");
        }else{
            if(!checkDayRule(Integer.valueOf(receiveDefaultDay))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-领取默认天数范围应在0~99！");
            }
        }
        vo = new SplPriSeaRuleCfgVO();
        vo.setPrivateSeaNm(privateSeaNm);
        vo.setBuOrgCd(buOrgCd);
        vo.setReceiveLimitUp(Long.valueOf(receiveLimitUp));
        vo.setIsCanReceive(Integer.valueOf(isCanReceive));
        vo.setReceiveDefaultDay(Long.valueOf(receiveDefaultDay));
        if(StringUtils.isNotEmpty(receiveLimitUp) && Integer.valueOf(receiveLimitUp) > 0){
            vo.setIsLimitUp(BaseConstant.IS_YESNO_YES);
        }else{
            vo.setIsLimitUp(BaseConstant.IS_YESNO_NO);
        }
        if(StringUtils.isNotEmpty(unvisitReleaseDay)){
            if(!checkDayRule(Integer.valueOf(unvisitReleaseDay))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-未拜访释放天数范围应在0~99！");
            }
            vo.setUnvisitReleaseDay(Long.valueOf(unvisitReleaseDay));
        }else{
            vo.setUnvisitReleaseDay(-1L);
        }
        if(StringUtils.isNotEmpty(uncapReleaseDay)){
            if(!checkDayRule(Integer.valueOf(uncapReleaseDay))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-未放款释放天数范围应在0~99！");
            }
            vo.setUncapReleaseDay(Long.valueOf(uncapReleaseDay));
        }else{
            vo.setUncapReleaseDay(-1L);
        }
        if(StringUtils.isNotEmpty(hadCapedReleaseDay)){
            if(!checkDayRule(Integer.valueOf(hadCapedReleaseDay))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-距上一次放款没再次放款释放天数范围应在0~99！");
            }
            vo.setHadCapedReleaseDay(Long.valueOf(hadCapedReleaseDay));
        }else{
            vo.setHadCapedReleaseDay(-1L);
        }
        if(StringUtils.isNotEmpty(uncrtprjReleaseDay)){
            if(!checkDayRule(Integer.valueOf(uncrtprjReleaseDay))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-未立项的释放天数范围应在0~99！");
            }
            vo.setUncrtprjReleaseDay(Long.valueOf(uncrtprjReleaseDay));
        }else{
            vo.setUncrtprjReleaseDay(-1L);
        }
        if(StringUtils.isNotEmpty(releasedReceiveDay)){
            if(!checkDayRule(Integer.valueOf(releasedReceiveDay))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-私海释放后,再次领取的天数限制,天数范围应在0~99！");
            }
            vo.setReleasedReceiveDay(Long.valueOf(releasedReceiveDay));
        }else{
            vo.setReleasedReceiveDay(-1L);
        }
        if(StringUtils.isNotEmpty(capDelayDate)){
            if(!checkDayRule(Integer.valueOf(capDelayDate))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-放款后延时天数范围应在0~99！");
            }
            vo.setCapDelayDate(Long.valueOf(capDelayDate));
        }else{
            vo.setCapDelayDate(-1L);
        }
        if(StringUtils.isNotEmpty(crtPrjDelayDate)){
            if(!checkDayRule(Integer.valueOf(crtPrjDelayDate))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-立项后延时天数范围应在0~99！");
            }
            vo.setCrtPrjDelayDate(Long.valueOf(crtPrjDelayDate));
        }else{
            vo.setCrtPrjDelayDate(-1L);
        }
        if(StringUtils.isNotEmpty(isAutoRelease)){
            vo.setIsAutoRelease(Integer.valueOf(isAutoRelease));
        }
        if(StringUtils.isNotEmpty(isActiveRelease)){
            vo.setIsActiveRelease(Integer.valueOf(isActiveRelease));
        }
        if(StringUtils.isNotEmpty(customersLimitUp)){
            /*if(!checkDayRule(Integer.valueOf(customersLimitUp))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-私海数量范围应在0~99内！");
            }*/
            vo.setCustomersLimitUp(Long.valueOf(customersLimitUp));
        }else{
            vo.setCustomersLimitUp(-1L);
        }
        if(StringUtils.isNotEmpty(visitRecDelayDate)){
            if(!checkDayRule(Integer.valueOf(visitRecDelayDate))){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_500,"私海规则-添加拜访记录后私海延时范围应在0~99内！");
            }
            vo.setVisitRecDelayDate(Long.valueOf(visitRecDelayDate));
        }else{
            vo.setVisitRecDelayDate(-1L);
        }
        if(StringUtils.isNotEmpty(autoRuleQCAndIsOr)){
            vo.setAutoRuleQCAndIsOr(Integer.parseInt(autoRuleQCAndIsOr));
        }else{
            vo.setAutoRuleQCAndIsOr(-1);
        }
        vo.setRemark(remark);
        vo.setIsDel(BaseConstant.IS_YESNO_NO);
        vo.setIsValid(BaseConstant.IS_YESNO_YES);
        return vo ;
    }

    private boolean checkDayRule(Integer day){
        if(day <= 0 || day > 99){
            return false;
        }
        return true ;
    }
}

